using System;
using System.Text;
using System.Collections.Generic;

namespace Demo_G.O.S.E.ServerEngine.AIEngine.Agent
{
    /// <summary>
    /// This is a wrapper around a ServerSocket.
    /// This is implemented as an Agent because of the Garbage Collecting capabilities built into the AgentThread.
    /// </summary>
    public class DaemonServer : DaemonService
    {
        /// <summary>
        /// A handle to the parent Daemon.
        /// </summary>
        private Daemon m_Daemon = null;

        /// <summary>
        /// The ServerSocket.
        /// </summary>
        //ServerSocket serverSocket = null;

        /// <summary>
        /// The port.
        /// </summary>
        private int m_iPort;

        /// <summary>
        /// Constructs a new DaemonServer for the given port.
        /// </summary>
        /// <param name="daemon"></param>
        /// <param name="port"></param>
        public DaemonServer(Daemon daemon, int port) : base(false)
        {
            this.m_Daemon = daemon;
            this.m_iPort = port;
            //serverSocket = new ServerSocket( port );
        }

        /// <summary>
        /// The main body of the DaemonServer.
        /// </summary>
        protected override void ExecuteAgent()
        {
            //try
            //{
            //    while ( true )
            //    {
            //        Socket socket = serverSocket.accept();
            //        daemon.addConnection( new DaemonSocket( daemon, socket ) );
            //    }
            //}
            //catch ( SocketException se )
            //{
            //    displayMessage( se.tostring() );
            //}
        }

        /// <summary>
        /// Returns a description of the service.
        /// </summary>
        public override string ShortDescription
        {
            get { return "ConnectionListener on " + m_iPort; }
        }

        /// <summary>
        /// Returns a description of the service.
        /// </summary>
        public override string AgentDescription
        {
            get { return ShortDescription; }
        }
    }
}